package cn.edu.imnu.controller;

import cn.edu.imnu.common.ResponseData;
import cn.edu.imnu.entry.dto.SaleDeleteDto;
import cn.edu.imnu.entry.dto.SaleUpdateDto;
import cn.edu.imnu.entry.vo.SaleRegionListVo;
import cn.edu.imnu.service.SaleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("region")
public class RegionController {
    @Resource
    private SaleService saleService;

    @GetMapping("getRegionList")
    public ResponseData<List<SaleRegionListVo>> getSaleRegionList(){
        List<SaleRegionListVo> RegionList = saleService.getRegionList();
        return ResponseData.ok(RegionList);
    }

    @PostMapping("deleteThisData")
    public ResponseData<String> deleteThisData(@RequestBody SaleDeleteDto saleDeleteDto){
        boolean success =saleService.deleteThisData(saleDeleteDto);

        if (success) {
            return ResponseData.ok("操作成功");
        }else {
            return ResponseData.warn("操作失败");
        }
    }

    @PostMapping("updateData")
    public ResponseData<String> updateData(@RequestBody SaleUpdateDto updateDto){
        boolean success = saleService.updateData(updateDto);

        if (success){
            return ResponseData.ok("操作成功");
        }else {
            return ResponseData.warn("操作失败");
        }
    }
}
